﻿using System.ComponentModel.DataAnnotations;

namespace Infrastructure.Extension
{
    /// <summary>
    /// 获取 name,value,remark 
    /// </summary>
    public static class EnumHelper
    {
        //public class EnumInfo
        //{
        //    /// <summary>
        //    /// displayName或者Description
        //    /// </summary>
        //    public string DisplayName { set; get; }
        //    public int Value { set; get; }
        //}
        public static string GetDisplayName<T>(this T item)
        {
            var objArr = item.GetType().GetField(item.ToString()).GetCustomAttributes(typeof(DisplayAttribute), true);
            if (objArr.Any())
            {
                var da = objArr[0] as DisplayAttribute;
                return da.Name;
            }
            return "";
        }
    }
}
